package com.lovo.pz.role;

import com.lovo.pz.util.GameUtil;
import com.lovo.pz.window.GamePanel;

import java.awt.*;

/**
 * 关卡进程角色
 * @author 白德柯
 *
 */
public class ProgressRole extends BaseRole{
    /** 进程对应的数值 */
    private int progressValue;
    public ProgressRole(Component component){
        super(component);

    }
    @Override
    public void initRole() {
        setRoleX(680);
        setRoleY(575);
        progressValue = 146;
    }

    @Override
    public void paintRole(Graphics g) {
        g.drawImage(GameUtil.flagMeterImage[1],getRoleX(),getRoleY(),getComponent());
        g.drawImage(GameUtil.flagMeterImage[0],getRoleX(),getRoleY()
                ,getRoleX() + progressValue,getRoleY() + 21,
                0,0,progressValue,21,getComponent());
        g.drawImage(GameUtil.flagMeterLevelProgressImage,
                getRoleX() + 40,getRoleY() + 13,getComponent());
        g.drawImage(GameUtil.flagMeterParts2Image,getRoleX() + 80,getRoleY(),getComponent());
        g.drawImage(GameUtil.flagMeterParts2Image,getRoleX() + 20,getRoleY(),getComponent());
        g.drawImage(GameUtil.flagMeterParts1Image,getRoleX() + progressValue,getRoleY()
                ,getComponent());
        if(getRunStatus() == BaseRole.MORE_ZOMBIE_COME){
            g.drawImage(GameUtil.largeWaveImage,300,300,getComponent());
        }
    }

    @Override
    public void action() {
        if(progressValue > 0){
            if(GameUtil.delay(1000,this,"progress")){
                progressValue--;
                if(progressValue == 80){
                    GameUtil.generateZombie((GamePanel) getComponent(),50);
                    this.setRunStatus(BaseRole.MORE_ZOMBIE_COME);
                }
            }
        }
        if(getRunStatus() == BaseRole.MORE_ZOMBIE_COME){
            if(GameUtil.delay(5000,this,"moreZombieCome")){
                this.setRunStatus(BaseRole.NORMAL);
            }
        }
    }
}
